package com.flong.juc.charter1;

import lombok.Data;
import lombok.SneakyThrows;

/**
 * @Author:liangjl
 * @Date: 2020/7/4-20:39
 * @Eamil:jilongliang@sina.com
 * @Description:
 *
 * 打印出来 ：username=周伯通password=888888
 */
public class MyTest4 {
    @SneakyThrows
    public static void main(String[] args) {
        MyTest4User user = new MyTest4User();
        Thread thread = new MyTest4Thread(user);
        thread.start();
        //停留5秒钟
        Thread.sleep(5000);
        thread.stop();

        System.out.println("username=" + user.getUsername() + "password=" + user.getPassword());
    }
}


class MyTest4Thread extends Thread {
    private MyTest4User user;

    public MyTest4Thread(MyTest4User user) {
        this.user = user;
    }


    @Override
    public void run() {
        user.updateUser("周伯通", "90000");
    }
}

@Data
class MyTest4User {
    private String username = "瑛姑";
    private String password = "888888";

    synchronized public void updateUser(String username, String password) {
        this.username = username;
        try {
            //停留10秒钟
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.password = password;
    }

}